public class HashBuck<K, V> {//写成泛型
    static class Node<K,V>{
        private K key;
        private V val;
        private Node<K,V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }
    public Node<K,V>[] array = (Node<K,V>[])new Node[10];
    public int usedSize;
    public HashBuck(){};
    public  void put(K key, V val){
        Node<K,V> node = new Node<K,V>(key,val);
        int hash = key.hashCode();//获取key的hashcode值（key为自定义的数据类型，需要用hashcode将其转换为整数，然后求余找到所储存的位置）
        int index = hash % array.length;
        Node<K,V> cur = array[index];
        //Map里面如果插入的元素的key与原本Map里面某个元素的key相同，此时会进行value的覆盖
        while (cur != null){
            if (cur.key.equals(key)){//比较每个具体的值
                cur.val = val;
                return;//替换完成
            }
            cur = cur.next;
        }
        //将当前元素插入到当前array[index]所在的链表中去
        node.next = array[index];
        array[index] = node;
        usedSize++;
//        //计算负载因子
//        if (loadFactor() >= DEFAULT_LOAD_FACTOR){
//            //扩容
//            resize();
//        }
    }
    public V get(K key){
        int hash = key.hashCode();
        int index = hash % array.length;
        Node<K,V> cur = array[index];
        while (cur != null){
            if (cur.key.equals(key)){
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }

}
